package com.first.util;

import com.first.entity.Users;
import com.common.base.Result;
import com.kckj.comm.util.KckjLog;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author: 范超强
 * @date: 2021/4/12
 */
@Aspect
@Component
@Slf4j
public class LogAspect {
    @Pointcut("execution(public * com.first.controller.*.*(..))")
    public void LogAspect(){}

    @Before("LogAspect()")
    public void doBefore(JoinPoint joinPoint){
        System.out.println("&&&&&&&&&&&&&&&"+joinPoint.toString());
        System.out.println("***************doBefore");
    }

    @After("LogAspect()")
    public void doAfter(JoinPoint joinPoint){
        System.out.println("^^^^^^^^^^^^^^^^"+joinPoint);
        System.out.println("****************doAfter");
    }

    @AfterReturning(value = "@annotation(point)",returning = "result")
    public void doAfterReturning(JoinPoint joinPoint,KckjLog point,Object result){
//        List<Users> list = (List<Users>) ret;
//        for (Users users : list) {
//            System.out.println("result----{}"+users.toString());
//        }
//        Map<String,String> map = (Map<String, String>) joinPoint.getArgs()[0];
//        System.out.println("args+++++++++++{}"+map);
        System.out.println("*****************doAfterReturning"+point);
    }

    @AfterThrowing("LogAspect()")
    public void deAfterThrowing(JoinPoint joinPoint){
        System.out.println("******************deAfterThrowing");
    }

    @Around("LogAspect()")
    public Object deAround(ProceedingJoinPoint joinPoint) throws Throwable{
        System.out.println("******************deAround");
        return joinPoint.proceed();
    }
}
